<template>
  <el-form
    :model="formData"
    ref="advancedFormRef"
    label-width="100px"
    size="small"
  >
    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="开始日期" prop="start_date">
          <el-date-picker
            v-model="formData.start_date"
            type="date"
            placeholder="选择开始日期"
            value-format="YYYY-MM-DD"
          ></el-date-picker>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="结束日期" prop="end_date">
          <el-date-picker
            v-model="formData.end_date"
            type="date"
            placeholder="选择结束日期"
            value-format="YYYY-MM-DD"
          ></el-date-picker>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="资产组" prop="asset_group">
          <el-select
            v-model="formData.asset_group"
            placeholder="选择资产组"
            clearable
          >
            <el-option label="服务器组" value="server"></el-option>
            <el-option label="网络设备组" value="network"></el-option>
            <el-option label="终端设备组" value="terminal"></el-option>
            <el-option label="安全设备组" value="security"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="操作人" prop="operator">
          <el-input
            v-model="formData.operator"
            placeholder="输入操作人"
            clearable
          ></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="是否有变更" prop="has_change">
          <el-select
            v-model="formData.has_change"
            placeholder="选择是否有变更"
            clearable
          >
            <el-option label="有变更" value="true"></el-option>
            <el-option label="无变更" value="false"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="涉及维度" prop="dimension">
          <el-select
            v-model="formData.dimension"
            placeholder="选择涉及维度"
            clearable
          >
            <el-option label="合规状态" value="compliance"></el-option>
            <el-option label="漏洞风险" value="vulnerability"></el-option>
            <el-option label="威胁情报" value="intelligence"></el-option>
            <el-option label="高危端口" value="high_risk_port"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>

    <div class="form-actions">
      <el-button type="primary" @click="handleConfirm">确认</el-button>
      <el-button @click="handleReset">重置</el-button>
    </div>
  </el-form>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits, onMounted } from "vue";
import { ElForm } from "element-plus";

// 定义属性和事件
const props = defineProps({
  formData: {
    type: Object,
    default: () => ({
      start_date: "",
      end_date: "",
      asset_group: "",
      operator: "",
      has_change: "",
      dimension: "",
    }),
  },
});

const emit = defineEmits(["confirm", "reset"]);

// 表单引用
const advancedFormRef = ref<InstanceType<typeof ElForm>>();

// 表单数据
const formData = ref({ ...props.formData });

// 监听父组件表单数据变化
onMounted(() => {
  formData.value = { ...props.formData };
});

// 事件处理 - 确认
const handleConfirm = () => {
  emit("confirm", formData.value);
};

// 事件处理 - 重置
const handleReset = () => {
  formData.value = {
    start_date: "",
    end_date: "",
    asset_group: "",
    operator: "",
    has_change: "",
    dimension: "",
  };
  emit("reset");
};
</script>

<style scoped lang="scss">
.form-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}
</style>
